<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let str="http://www.baidu.com?a=1&b=2&c=3&d=4";
        str=str.substring(str.indexOf('?')+1);
        //console.log(str);//a=1&b=2&c=3&d=4
        // console.log("{"+str.replace(/&/g,",").replace(/=/g,":")+"}");//{a:1,b:2,c:3,d:4}
        str="{"+str.replace(/&/g,",").replace(/=/g,":")+"}";
        console.log(eval('('+str+')'));
    </script>

    eval函数:
    eval函数可以将括号里面的字符串当中的js代码进行解析
    <script>
        eval('var a=1;var b=2;alert(a+b)');
        console.log(eval('{a:1}'));//1
    </script>
</body>
</html>